package com.xyy.saas.payment.dao.mapper;

import com.xyy.saas.payment.dao.model.FbankPayRecords;
import com.xyy.saas.payment.dao.model.FbankPayRecordsQueryParam;
import com.xyy.saas.payment.dto.ReconcileTradeDto;
import com.xyy.saas.payment.dto.TradeAmountDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface FbankPayRecordsMapper {

    long getTotal(FbankPayRecordsQueryParam param);

    int insertSelective(FbankPayRecords record);

    List<FbankPayRecords> queryAllByParam(FbankPayRecordsQueryParam param);

    List<FbankPayRecords> pageAllByParam(FbankPayRecordsQueryParam param);

    FbankPayRecords queryByOrderNo(String orderNo);

    FbankPayRecords queryByBusinessNo(@Param("businessNo") String businessNo);

    FbankPayRecords queryOneByBusinessNoAndTradeCodes(@Param("businessNo") String businessNo, @Param("tradeCodes") List<Integer> tradeCodes);

    int deleteById(Long id);

    /**
     * 查询fbank单边
     */
    List<FbankPayRecords> queryFbankSingleSideWithSeparateOrder(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                                @Param("tradeCodes") List<Integer> tradeCodes);

    /**
     * fbank单边
     */
    List<FbankPayRecords> queryFbankSingleSideWithRefund(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime);

    /**
     * fbank、SeparateOrder 错账
     */
    List<ReconcileTradeDto> queryFbank2SeparateOrderErrorAmountRecords(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                                       @Param("tradeCodes") List<Integer> tradeCodes);

    /**
     * fbank、SeparateOrder 错账
     */
    List<ReconcileTradeDto> queryFbank2SeparateOrderErrorAmountWithRefundRecords(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime);

    List<FbankPayRecords> queryFbankSingleSideWithPayResult(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                            @Param("tradeCodes") List<Integer> tradeCodes, @Param("excludeAccountIds") List<String> tradeCheckExcludeAccountIds);

    List<ReconcileTradeDto> queryFbank2PayResultErrorAmountRecords(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                                   @Param("tradeCodes") List<Integer> tradeCodes, @Param("excludeAccountIds") List<String> tradeCheckExcludeAccountIds);

    @Deprecated
    List<FbankPayRecords> queryFbankSingleSideWithRefundOrder(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                              @Param("tradeCodes") List<Integer> tradeCodes);

    List<FbankPayRecords> queryFbankSingleSideWithRefundOrder2(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                              @Param("tradeCodes") List<Integer> tradeCodes, @Param("excludeAccountIds") List<String> tradeCheckExcludeAccountIds);

    List<ReconcileTradeDto> queryFbank2RefundOrderErrorAmountDtos(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime,
                                                                  @Param("tradeCodes") List<Integer> tradeCodes, @Param("excludeAccountIds") List<String> tradeCheckExcludeAccountIds);

    List<TradeAmountDto> queryInTotalAmountByTradeCode(@Param("accountId") String accountId, @Param("beginTime") LocalDateTime beginTime,
                                                       @Param("endTime") LocalDateTime endTime, @Param("tradeCodes") List<Integer> tradeCodes);

    List<TradeAmountDto> queryOutTotalAmountByTradeCode(@Param("accountId") String accountId, @Param("beginTime") LocalDateTime beginTime,
                                                        @Param("endTime") LocalDateTime endTime, @Param("tradeCodes") List<Integer> tradeCodes);
}